﻿using Microsoft.AspNetCore.Mvc;
using Single.Core.Service;
using Single.Sys.Entity;
using Single.WebApp.Components;

namespace Single.WebApp.Areas.Sys.Controllers
{
    [Area("Sys")]
    public class MenuController : WorkController
    {
        public IActionResult Index()
        {
            return View();
        }

        public string Get(long id)
        {
            var entity = ServiceSysProps.SysMenu.Get(id);

            return ServiceResult.SerializeData(entity);
        }

        public string GetData(string title, string src)
        {
            var rows = ServiceSysProps.SysMenu.GetData(title, src);

            return ServiceResult.SerializeData(new { rows });
        }

        public string Save(SysMenu entity)
        {
            return ServiceSysProps.SysMenu.InsertOrUpdate(entity).Serialize();
        }

        public string Delete(long[] ids)
        {
            return ServiceSysProps.SysMenu.Delete(ids).Serialize();
        }

        public string GetFunction()
        {
            var rows = ServiceSysProps.SysFunction.GetAll();

            return ServiceResult.SerializeData(new { rows });
        }

        public string GetFunctionByMenuId(long id)
        {
            var rows = ServiceSysProps.SysMenuFunction.GetByMenuId(id);

            return ServiceResult.SerializeData(new { rows });
        }

        public string Assign(long menuId, List<SysMenuFunction> rows)
        {
            return ServiceSysProps.SysMenuFunction.Assign(menuId, rows).Serialize();
        }
    }
}